//@author A0096466N
//
// **********
//
// reminder class takes in the entire store of tasks via vector<Task>
// and returns the tasks to be reminded via vector<Task>
//
// does not remind done/archive tasks
// reminds if <=1 day and low priority
// reminds if <=2 days and medium priority
// reminds if <=3 days and high priority
//
// **********

#include "Reminder.h"

Reminder::Reminder(void) { 

}

Reminder::~Reminder(void) {

}

vector <Task> Reminder::execute(vector<Task> store) {
 
	ofstream writeFile;
	writeFile.open(FILENAME_LOGGER.c_str(), ofstream::out | ofstream::app);
	writeFile << "Attempting to remind" << endl;
	writeFile.close();

        time_t rawtime;
        time(&rawtime);  /* current time in seconds */
 
        struct tm * currentTime;
 
        currentTime = localtime(&rawtime);
 
		// making current time point to today at 00:00
        (*currentTime).tm_hour = 0;                             
        (*currentTime).tm_min = 0;
        (*currentTime).tm_sec = 0;
 
        time_t today = mktime(currentTime);
 
        vector<Task> toBeReminded;
 
        for(vector<Task>::iterator iter = store.begin(); iter != store.end(); iter++) {
			if((*iter).getStatus() == CMI) {
				toBeReminded.push_back(*iter);
			
			} else if((*iter).getStatus() != DONE && (*iter).getStatus() != ARCHIVE) {
				time_t deadline = (*iter).getDateInSeconds();
                if(difftime(deadline,today) <= 60*60*24*3 && (*iter).getPriority() == "high") {
                        toBeReminded.push_back(*iter);
                } else if(difftime(deadline,today) <= 60*60*24*2 && (*iter).getPriority() == "medium") {
                        toBeReminded.push_back(*iter);
                } else if(difftime(deadline,today) <= 60*60*24*1 && (*iter).getPriority() == "low") {
                        toBeReminded.push_back(*iter);
				} else if(difftime(deadline,today) <= 60*60*24*1 && (*iter).getPriority() == "") {
                        toBeReminded.push_back(*iter);
                }
 		    }
 		}
        return toBeReminded;
 }
 